Pressidian
花园入口
笔记
项目
关于
实验室
GitHub
花园入口
笔记
项目
关于
实验室
GitHub

KNOWLEDGE PATHS

笔记库
当前位置
笔记库/前端/三件套/样式/CSS/MDN文档/1 基础样式/8 图像、媒体与表单

Challenge: Styling a home color scheme search app

26 分钟阅读 · Note

目录树 578 篇

                  • 挑战:图片和表格元素
                  • 图像、媒体和表单元素
                  • 样式化表格
                  • Challenge: Styling a home color scheme search app
          • tailwindCSS
      • 前端技术栈
    • 笔记目录
    • CLAUDE.md
    • Vue 组件与 Render 函数

关联笔记 6

↗挑战:图片和表格元素同一路径↗图像、媒体和表单元素同一路径↗样式化表格同一路径↗背景与边框共同主题↗测试你的技能:CSS 样式基础共同主题↗层叠、优先级与继承共同主题
  • Challenge: Styling a home color scheme search app

Challenge: Styling a home color scheme search app

  • Previous
  • Overview: CSS styling basics
  • Next

The final challenge of our styling basics module features a mockup of a "Home color search app" UI, the idea being to let users input a color and retrieve a range of variations along with sample color scheme ideas. Your task is to style the provided form, table, and button controls, and make sure the images display as expected.

Note: The tinted images used in this challenge have been adapted from the original available on Flickr: Chic Living Room, published by Houseology Interiors under CC BY-NC 2.0.

In this article

  • Starting point
  • Project brief
  • Hints and tips
  • Example

[Mozilla Data Collective

Get open datasetsThe language datasets you've been missingJoin Now

](https://developer.mozilla.org/pong/click?code=aHR0cHM6Ly9zcnYuYnV5c2VsbGFkcy5jb20vYWRzL2NsaWNrL3gvR1RORDQyN1VDWUJJS0szTkY2U0xZS1FVQ0FTSTQySllDVjdEQ1ozSkNBU0k1S0o3RlQ3SVRLSktGVDdJVjUzTkNLWUk1MlE3Q0FCRDY1M0VGNjdJNTVRS0M2U0k1MkpOQzZZREVLM0VISk5DTFNJWg%3D%3D.vux%2Ft%2BaEk%2F1lYtYpTjmwQ8yQdcSutI7PKuP32IPXPEI%3D&version=2)Ad

Starting point

To begin, click the Play button in one of the code panels below to open the provided example in the MDN Playground. You'll then follow the instructions in the Project brief section to style the page appropriately.

htmlCopyPlay

<section>
  <h1>Home color search</h1>
  <form>
    <div>
      <label for="color">Color to search for:</label>
      <input type="text" id="color" name="color" value="pink" />
    </div>
    <div>
      <label for="results-per-page">Results per page:</label>
      <input
        type="text"
        id="results-per-page"
        name="results-per-page"
        value="4" />
    </div>
    <div>
      <button type="button">Submit</button>
    </div>
  </form>
</section>
<hr />
<section>
  <h2>Search results</h2>
  <table>
    <caption>
      Sample colors and color schemes
    </caption>
    <thead>
      <tr>
        <th scope="col">Color</th>
        <th scope="col">Raw color</th>
        <th scope="col">Tags</th>
        <th scope="col">Sample color scheme</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Pink</td>
        <td><code>rgb(255 192 203)</code></td>
        <td>pink, pale, light</td>
        <td>
          <img
            src="https://mdn.github.io/shared-assets/images/examples/learn/home-color-schemes/living-room-pink.png"
            alt="Image of living room in a pink color scheme" />
        </td>
      </tr>
      <tr>
        <td>Baker-Miller pink</td>
        <td><code>rgb(255 145 175)</code></td>
        <td>pink, pale, bright</td>
        <td>
          <img
            src="https://mdn.github.io/shared-assets/images/examples/learn/home-color-schemes/living-room-baker-miller-pink.png"
            alt="Image of living room in a Baker-Miller pink color scheme" />
        </td>
      </tr>
      <tr>
        <td>Hotpink</td>
        <td><code>rgb(255 105 180)</code></td>
        <td>pink, bright, vivid</td>
        <td>
          <img
            src="https://mdn.github.io/shared-assets/images/examples/learn/home-color-schemes/living-room-hotpink.png"
            alt="Image of living room in a hotpink color scheme" />
        </td>
      </tr>
      <tr>
        <td>Fuchsia</td>
        <td><code>rgb(255 0 255)</code></td>
        <td>pink, medium, bright</td>
        <td>
          <img
            src="https://mdn.github.io/shared-assets/images/examples/learn/home-color-schemes/living-room-fuchsia.png"
            alt="Image of living room in a fuchsia color scheme" />
        </td>
      </tr>
    </tbody>
  </table>
  <div class="controls">
    <button disabled>Previous</button>
    <p>Showing page 1 of 20</p>
    <button>Next</button>
  </div>
</section>

cssCopyPlay

* {
  box-sizing: border-box;
}

html {
  font-family: "Helvetica", "Arial", sans-serif;
}

body {
  margin: 0 10px;
}

hr {
  margin: 3em 0;
}

h2 {
  margin-top: 0;
}

/* Prev/next control layout */

.controls {
  display: flex;
  padding: 10px 0;
  justify-content: space-between;
  align-items: center;
}

/* Form and button styling */

form div {
  display: flex;
  align-items: center;
  gap: 2em;
  margin-bottom: 1em;
}

label {
  text-align: right;
  flex: 1;
}

input {
  flex: 3;
}

/* Table styling */

table img {
  width: 100%;
  height: 150px;
}

Play

Project brief

Follow the steps below to complete the project, sizing the content pane appropriately and adding the required decorations.

Add a form reset

First of all, add some "reset" styles to the &lt;button&gt; and &lt;input&gt; elements to give them a consistent starting state across browsers.

Specifically:

  1. Make them inherit the font family set on the rest of the page.
  2. Give them a font size of 100%.
  3. Remove all their padding and margin.

Style the form inputs

Give the &lt;input&gt; elements:

  1. A 2px solid border with the color #999999.
  2. 10px of padding.
  3. 5px rounded corners.

Style the buttons

Give the &lt;button&gt; elements:

  1. No border.
  2. A black background color and white text color.
  3. 5px rounded corners.
  4. Vertical padding of 10px and horizontal padding of 2em.
  5. A background color of #666666 when hovered or focused.
  6. A background color of #aaaaaa when disabled.

Style the table

You should now add some best practice styling to the table, as learned earlier in the module, plus a few extras.

Specifically:

  1. Give the table a fixed layout, a width of 100%, and collapsed borders.
  2. Make the table's top and bottom borders 1px thick, solid, and colored #999999.
  3. Give the table header cells and normal cells 0.6em of padding, and make their content vertically aligned to the top of the cells.
  4. Give the table header cells a bottom border that is 1px thick, solid, and colored #999999.
  5. Give all of the table rows a width of 20%, except for the fourth row, which should have a width of 40%.
  6. Inside the table body, there are four rows. The second cell inside each of these rows contains text for an rgb() color. Give each one of these cells a background color that corresponds to its text.
  7. Create zebra stripes: Give each odd-numbered row a background color of #eeeeee, inside the table body only.
  8. Give the caption padding of 1em, an italic font style, and letter spacing of 1px.

Fixing the image display

At this point, there is a problem with the images in the table — we've set each image to 100% of the width of its table cell container, and a specific height of 150px, as we didn't want the table rows to get too high. However, this has distorted the aspect ratio of the images, making them look a bit squashed.

We'd like you to style the images so that:

  1. They are displayed at their intrinsic aspect ratio, but with a bit of the image cut off so they still fit inside the size of the &lt;img&gt; elements.
  2. The bottom of the image is shown, but the top of the image is cut off.

Hints and tips

  • You don't need to alter the HTML in any way.

Example

The finished project should look like this:

Play

Click here to show the solution

A possible solution could be:

  • Previous
  • Overview: CSS styling basics
  • Next

Help improve MDN

Was this page helpful to you?

YesNo

Learn how to contribute

This page was last modified on Oct 17, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content

Filter sidebar

  1. Learn web development

  2. MDN curriculum

  3. Getting started modules

  4. Environment setup

  5. Your first website

  6. Web standards

  7. Soft skills

  8. Core modules

  9. Structuring content with HTML

    1. Basic HTML syntax

    2. Web page metadata

    3. Headings and paragraphs

    4. Emphasis and importance

    5. Lists

    6. Test: HTML text basics

    7. Advanced text features

    8. Test: Advanced HTML text

    9. Challenge: Letter markup

    10. Structuring documents

    11. Creating links

    12. Test: Links

    13. Challenge: Bird watching site

    14. Images

    15. Test: Images

    16. Video and audio

    17. Test: Audio and video

    18. Challenge: Splash page

    19. Table basics

    20. Table accessibility

    21. Challenge: Planet data table

    22. Forms and buttons

    23. Test: Forms and buttons

    24. Challenge: Feedback form

    25. Debugging HTML

    26. Test: HTML tests index

    27. Additional tutorials

  10. CSS styling basics

    1. What is CSS?

    2. CSS getting started

    3. Challenge: Biography page

    4. Basic selectors

    5. Attribute selectors

    6. Pseudo-classes and elements

    7. Combinators

    8. Test: Selectors

    9. Box model

    10. Test: Box model

    11. Handling conflicts

    12. Test: Cascade

    13. Challenge: Fixing blog styles

    14. Values and units

    15. Test: Values and units

    16. Sizing

    17. Test: Sizing

    18. Backgrounds and borders

    19. Test: Backgrounds and borders

    20. Overflow

    21. Test: Overflow

    22. Challenge: Sizing and decorating

    23. Images, media, forms

    24. Test: Images and forms

    25. Styling tables

    26. Challenge: Styling color scheme search

    27. Debugging CSS

    28. Test: Styling basics tests index

    29. Additional tutorials

  11. CSS text styling

  12. CSS layout

    1. Introduction

    2. Floats

    3. Test: Floats

    4. Positioning

    5. Test: Positioning

    6. Flexbox

    7. Test: Flexbox

    8. CSS grid layout

    9. Test: CSS grid

    10. Challenge: Fundamental layout

    11. Responsive web design

    12. Media queries

    13. Test: RWD & media queries

    14. Challenge: mobile-first

    15. Test: Layout tests index

    16. Additional tutorials

  13. Dynamic scripting with JavaScript

  14. JavaScript frameworks and libraries

  15. Accessibility

  16. Design for developers

  17. Version control

  18. Extension modules

  19. Advanced JavaScript objects

  20. Client-side web APIs

  21. Asynchronous JavaScript

  22. Web forms

    1. Your first form

    2. How to structure a web form

    3. Basic native form controls

    4. The HTML5 input types

    5. Other form controls

    6. Styling web forms

    7. Advanced form styling

    8. Customizable selects

    9. Customizable listboxes

    10. UI pseudo-classes

    11. Client-side form validation

    12. Sending form data

    13. Additional tutorials

  23. Understanding client-side tools

  24. Server-side websites

    1. First steps

    2. Django (Python)

    3. Express (Node.js)

    4. Additional tutorials

  25. Web performance

  26. Testing

  27. Further resources

  28. How to solve common problems

  29. About

  30. Resources for educators

  31. Changelog

MongoDB AtlasAd

Your blueprint for a better internet.

MDN

  • About
  • Blog
  • Mozilla careers
  • Advertise with us
  • MDN Plus
  • Product help

Contribute

  • MDN Community
  • Community resources
  • Writing guidelines
  • MDN Discord
  • MDN on GitHub

Developers

  • Web technologies
  • Learn web development
  • Guides
  • Tutorials
  • Glossary
  • Hacks blog

  • Website Privacy Notice
  • Telemetry Settings
  • Legal
  • Community Participation Guidelines

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.